import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-05-20
 * Time: 0:21
 */
public class test3 {
    public ListNode reverseList(ListNode head) {
        ListNode newNode = new ListNode(0);
        ListNode cur = head;
        while(cur!=null){
            ListNode curNext = cur.next;

            cur.next = newNode.next;
            newNode.next = cur;
            // 移动cur到下一个
            cur = curNext;
        }
        return newNode.next;
    }


    public class ListNode{
        int val;
        ListNode next;
        ListNode(){

        }

        ListNode(ListNode next,int val){
            this.val = val;
            this.next = next;
        }

        ListNode(int val){
            this.val = val;
        }
    }
}
